package com.cskaoyan.controller;

import com.cskaoyan.bean.BaseRespVo;
import com.cskaoyan.bean.bo.CommentBO;
import com.cskaoyan.bean.bo.CommentReplyBO;
import com.cskaoyan.bean.param.BaseParam;
import com.cskaoyan.bean.vo.CommentVO;
import com.cskaoyan.bean.vo.TVO;
import com.cskaoyan.service.CommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author by WANGJun
 * @date 2022/6/5 22:24
 */
@RestController
@RequestMapping("admin/comment")
public class CommentController {

    @Autowired
    CommentService commentService;

    @RequestMapping("list")
    public BaseRespVo list(BaseParam baseParam,Integer userId, Integer valueId) {
        TVO<CommentVO> commentVOTVO = commentService.list(baseParam, userId, valueId);
        return BaseRespVo.ok(commentVOTVO);
    }

    @RequestMapping("delete")
    public BaseRespVo delete(@RequestBody CommentBO commentBO) {
        commentService.delete(commentBO.getId());
        return BaseRespVo.ok(null);
    }

    @RequestMapping("reply")
    public BaseRespVo reply(@RequestBody CommentReplyBO commentReplyBO) {
        int reply = commentService.reply(commentReplyBO);
        if (reply == 0) {
            return BaseRespVo.invalidParameter("该评论已回复!");
        }
        return BaseRespVo.ok(null);
    }
}
